﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebUI.DAL;
using WebUI.BL.News;

namespace WebUI.UserControls
{
    public partial class UCCreateCategory : System.Web.UI.UserControl
    {
        public string Id { get; set; }
        public string Lang { get; set;}

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindingModel();
            }
        }

        private tbl_NewsCategory FindNewsCategory()
        {
            int No = 0;
            Int32.TryParse(Id, out No);
            NewsCategoryBL repository = new NewsCategoryBL();
            var x = repository.GetNewsCategoryById(No);
            return x;
        }

        private  void BindingModel()
        {
            if(!String.IsNullOrEmpty(Id))
            {
                var model = FindNewsCategory();
                TextBox txtName = (TextBox) UcNameDescription1.FindControl("txtName");
                CKEditor.NET.CKEditorControl txtDescription = (CKEditor.NET.CKEditorControl)UcNameDescription1.FindControl("ckey1");
                txtName.Text = model.CategoryName;
                txtDescription.Text = model.Description;
                drpStatus.Text = model.Status;
                txtCreateUser.Text = model.CreatedUser;
            }
        }

        private void Update(string id,string lang)
        {
            
        }

        protected void btnClickSave(object sender, EventArgs e)
        {
            
            Response.Redirect(Helpers.link.toAdminNewsCategory("NewsCategory.aspx"));
        }
    }
}